/**
 * @author liubaohui
 * @desc 预览文件
 * @param fileID 必传
 * @param fileSize 可传，用来判断大小是否可以预览
 * @param fileName 可传，用来判断格式是否可以预览
 */
import store from '../store'

export default function previewFile(fileID, fileSize, fileName) {
  if (fileName && !this.$checkPreviewName(fileName)) {
    return this.$message.error({
      message: '文件格式不支持预览',
      duration: 1500,
      center: true
    })
  }
  if (fileSize && !this.$checkPreviewSize(fileSize)) {
    return this.$message.error({
      message: '预览文件大小不能超过15M',
      duration: 1500,
      center: true
    })
  }
  preview(fileID)
}

// 预览文件
function preview(fileID) {
  const ip = store.state.userInfo.webServerIP
  const port = store.state.userInfo.webServerPort
  const addr = `//${ip}:${port}/a/uploadhistory/uploadHistory/preview/${fileID}`
  window.open(addr)
}
